<?php session_start();
validaAcesso();
require_once"funcoes/com_hostels.jsp";
  echo"<form method='POST' action='index.jsp?config=4&cont=1' autocomplete='off'>
      <h2>Libera&ccedil;&atilde;o de Acessos aos Funcion&aacute;rios</h2>
      Unidade:<BR>
      <select name='pid_hostel'>";
      getHostels($_SESSION["ID_HOSTEL_"],"select");
        echo"</select> <input type='submit' value='selecionar'></form>";

if($_GET["cont"]==1) {
             $novo_id_hostel=trim($_POST["pid_hostel"]);

             $sql="
             select
                a.nome_pessoa,
                b.nome_hostel,
                a.tipo,
                a.id_pessoa,
                a.login

             from
                pes_pessoas a
                left join com_hostels b on (a.id_hostel=b.id_hostel)
             where
             (a.tipo = 'F') and
             (a.id_hostel = $novo_id_hostel)
             order by b.nome_hostel, a.nome_pessoa asc
             ";
             $ln=$_SESSION['ADOCnn']->Execute("$sql");
             $n=0;
             echo"<table class='perfil'>
                    <tr class='titulo'>
                      <td width=130>&nbsp;</td>
                      <td width='50'>ID</td>
                      <td width='100'>Login</td>
                      <td width='350'>Nome</td>
                      <td>Tipo</td>
                    </tr>
                    </table>
                    ";
	if($ln->RecordCount() != 0 ){
	while(!$ln->EOF){
                  $ant_hostel="$hostel";
                  $nome = htmlentities(trim($ln->fields[0]));
                  $hostel = htmlentities(trim($ln->fields[1]));
                  $TIPO = $ln->fields[2];
                  $id   = $ln->fields[3];
                  $login= $ln->fields[4];

                if($TIPO=="F"){$TIPO="Funcion&aacute;rio";}
                if($TIPO=="H"){$TIPO="H&oacute;spede";}

                if($ant_hostel!=$hostel){echo"<h2>$hostel</h2>";}
                echo"<table class='perfil'>
                  <tr>
                      <td width=130><a href='index.jsp?config=4&cont=2&id_pessoa=$id'><img src='images/btn_selecionar.gif' border='0'></a></td>
                      <td width='50' align='center'>$id</td>
                      <td width=100>$login</td>
                      <td width=350>$nome</td>
                      <td>$TIPO</td>
                   </tr>
                   </table>
                ";
                $n++;
 				$ln->MoveNext();
				}
             }

             echo"<br><b>Resultados:</b> <u>$n</u>";

}elseif($_GET["cont"]==2){
   getAcessos($_GET["id_pessoa"]);
}elseif($_GET["cont"]==3){
   gravaAcessos($_POST);
}
?>

